package algorithm.easy;

import java.util.HashMap;
import java.util.Map;

public class Solution171 {
    //A -> 1
    //B -> 2
    //C -> 3
    //...
    //Z -> 26
    //AA -> 27
    //AB -> 28
    //输入: columnTitle = "A"
    //输出: 1
    //输入: columnTitle = "AB"
    //输出: 28
    public static  int titleToNumber(String columnTitle) {
        Map<Character,Integer> map = new HashMap<>();
        for(int i=1;i<=26;i++){
            map.put((char)(i+64),i);
        }
        char[] chr = columnTitle.toCharArray();
        int res = 0;
        for(int i=0;i<chr.length;i++){
            res = res*26 + map.get(chr[i]);
        }
        return res;
    }

    public static void main(String[] args){
     String columnTitle = "FXSHRXW";
     System.out.println(titleToNumber(columnTitle));
    }

}
